﻿<?xml version="1.0" encoding="UTF-8"?>
<html>
    <head>
        <link type="text/css" rel="stylesheet" href="./css/template.css" />
        <link type="text/css" rel="stylesheet" href="./css/SyntaxHighlighter.css" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Java for Mobiles - J2ME</title>
        <keywords>J2ME,presentation,CLDC,MIDP,midlet,Java,Java ME,java,for,mobile,j2me, articles, 1.1, certification, sun, Java, Solaris, articles, essential tips, tricks, codes,tutorial, development, jsp, servlet, jdbc, jdo, j2se, j2ee, laboratory</keywords>
        <author>Serhiy KVITKA</author>
        <script language="javascript" src="./js/shInit.js" />
        <script language="javascript" src="./js/shCore.js" />
        <script language="javascript" src="./js/shBrushCpp.js" />
        <script language="javascript" src="./js/shBrushCSharp.js" />
        <script language="javascript" src="./js/shBrushCss.js" />
        <script language="javascript" src="./js/shBrushDelphi.js" />
        <script language="javascript" src="./js/shBrushJava.js" />
        <script language="javascript" src="./js/shBrushJScript.js" />
        <script language="javascript" src="./js/shBrushPhp.js" />
        <script language="javascript" src="./js/shBrushPython.js" />
        <script language="javascript" src="./js/shBrushRuby.js" />
        <script language="javascript" src="./js/shBrushSql.js" />
        <script language="javascript" src="./js/shBrushVb.js" />
        <script language="javascript" src="./js/shBrushXml.js" />
    </head>
    <body>
        <div class="chapter">
            <p>﻿</p>
        </div>
        <!-- debut du contenu -->
        <div class="chapter">
            <h2>Java pour les Mobiles - J2ME</h2>
        </div>
        <div class="chapter">
            <h2>Introduction</h2>
            <p>
                Initially the Java 2 Platform Micro Edition (J2ME) was established to develop applications on equipment with limited resources independently, memory and processor such as mobile phones, smart cards, palms, the organizers and mini-computers.
                <br />
                The J2ME platform can build a Java Runtime Environment (JRE) complete, which adapts to the needs of resource-limited equipment.
                <br />
                J2ME introduced three major concepts : the configuration profiles and Midlet.
                <br />
                You can find detailed information on the official website of Sun Microsystems :
                <br />
            </p>
            <p>
                <i>
                    <span>
                        <a href="http://java.sun.com/j2me/" target="_blank">http://java.sun.com/j2me/</a>
                    </span>
                </i>
            </p>
            <br />
        </div>
        <div class="chapter">
            <h2>1.The configuration</h2>
            <p>
                It determines the midst of implementing J2ME. It includes a virtual machine limited compared to the standard VM and a number of main class borrowed from J2SE. 
Currently, there are two configurations determined :
                <br />
            </p>
            <ul>
                <li>Connected Limited Device Configuration (CLDC)</li>
                <li>Connected Device Configuration (CDC)</li>
            </ul>
            <p>
                The CLDC is oriented mini mobile equipped with 16/32 bit processors whose memory is 128 KB minimum.
                <br />
                The point advantage J2ME CLDC is a virtual machine K Virtual Machine (KMV), developed specifically for the network interfaces to memory and limited resources. 
		The CDC is oriented equipment greater capacity as: smart communicators, pagers, PDAs, Sony PlayStation, XBox, etc.). 
		The CDC is running the virtual machine C Virtual Machine (CVM).
                <br />
                The CDC is composed of all classes of CLDC most other classes of J2SE.
            </p>
        </div>
        <div class="chapter">
            <h2>2. Profile</h2>
            <p>The profile extends the configuration by adding specific classes the number of general classes, defined in their configuration. 
In other words, the profile provides the essential feature that is lacking in the general configuration. This may be a user interface, a safeguard mechanism, and so on. 
Apart from the profile MIDP (Mobile Information Device Profile) there are others.</p>
            <div class="subChapter">
                <h3>2.1. Foundation Profile</h3>
                <p>"Foundation Profile" is to add a number of classes J2SE CDC, but it is not introducing a user interface. 
			From this profile, built on other profiles.</p>
            </div>
            <div class="subChapter">
                <h3>2.2. Personal Basic Profile</h3>
                <p>"Personal Basic Profile" is used to ensure Java API for calling mobile network access and a graphic presentation. 
This profile is very useful for interactive television because it also contains an API for maintaining Multimedia Home Platform (JSR 129).</p>
            </div>
            <div class="subChapter">
                <h3>2.3. Personal Profile</h3>
                "Personal Profile" is used to ensure the support of the Java API for calling a mobile network access based on solid "Personal Basic Profile" and "Foundation Profile" (JSR62).
                <br />
                <p align="center">
                    <span style="font-size: 12.0pt; font-family: Times New Roman">
                        <img border="0" src="./images/21.bmp" />
                        <br />
                    </span>
                    <br />
                    <i>Architecture J2ME. * - Or development.</i>
                </p>
                <br />
            </div>
        </div>
        <div class="chapter">
            <h2>3. CLDC (Configuration mobile communication limited resources)</h2>
            <p>
                CLDC is the work of Java Community Process (JCP), a group of expert JSR-30, which represents the following companies:
                <br />
            </p>
            <ul>
                <li>Sun Microsystems</li>
                <li>America Online</li>
                <li>Bull</li>
                <li>Ericsson</li>
                <li>Fujitsu</li>
                <li>Matsushita</li>
                <li>Mitsubishi</li>
                <li>Motorola</li>
                <li>Nokia</li>
                <li>NTT DoCoMo</li>
                <li>Oracle</li>
                <li>Palm Computing</li>
                <li>RIM</li>
                <li>Samsung</li>
                <li>Sharp</li>
                <li>Siemens</li>
                <li>Sony</li>
                <li>Symbian</li>
            </ul>
            <p>
                The purpose of this technology is to determine a standard use of Java on mobile limited resources :
                <br />
            </p>
            <ul>
                <li>160-500 Kb of memory available to the Java platform</li>
                <li>A bit processor 16-32</li>
                <li>Low energy consumption</li>
                <li>connecting to networks from 9600 bps or less</li>
            </ul>
            <p>
                Below are presented aspects which fall under the "jurisdiction" CLDC :
                <br />
            </p>
            <ul>
                <li>Java language and virtual machine KVM</li>
                <li>Main Java libraries (java.lang.*, java.util.*)</li>
                <li>Security model</li>
                <li>Operation I/O</li>
                <li>Support Network</li>
                <li>Internalization</li>
            </ul>
            <p>
                The issues listed below are determined by profiles :
                <br />
            </p>
            <ul>
                <li>User Interface</li>
                <li>Treatment of events</li>
                <li>Validity of applications</li>
                <li>Liaison between a user and application</li>
                <ul />
            </ul>
        </div>
        <div class="chapter">
            <h2>4. The Java virtual machine and KVM</h2>
            <p>
                The goal for JVM, CLDC now is to be compatible with Java Language Specification as much as possible. Except for the differences cited below, JVM may be considered compatible with Java Language Specification.
                <br />
                There is no support for floating point type in the mobile limited resources. This is not because the floating point support level programming includes additional costs. There is no method finalize (), no weak references neither. This requirement is linked to the need to simplify the mechanism for cleaning. CLDC maintains the mechanism of emergency.
                <br />
                However, its capacity is limited for two reasons. The recovery is always an exception for each mobile (some of them set up only after all detected errors). The application can not handle those exceptions. The completed facility is too expensive for micro mobile.
            </p>
            <div class="subChapter">
                <h3>4.1. KVM</h3>
                <p>
                    The KVM does not support floating point. It does not exist in the mobile limited resources on the grounds that it would be too expensive to maintain programming level. In JVM CLDC now there has not byte code related to the types float and double.
                    <br />
                    The KVM does not Java Native Interface (JNI). The support JNI was rejected for several reasons. The security model CLDC prohibits the use of native calls. 
		    The realization of JNI was considered too expensive for mobile limited resources. The KVM does not create its class loader. This prohibition is imposed by the security model. 
		    The KVM does not support the mechanism of Reflection. The applications of Java can not inspect classes, objects, methods, fields, the son executed by the virtual machine. Therefore, technologies like JVMI (Debugging Interface), JVMPI (Profiler Interface) and other J2SE technology, based on the mechanism of Reflection are absent in CLDC.
                    <br />
		    The KVM directed the multiplex, but it does not support Thread groups and daemon threads. The operations such as launching and judgement may be 
		    Applied in only one Thread. He can not use the method finalize (), and weak references as this condition is essential that the mechanism for cleaning 
		    Is less complicated. The error handling mechanism is less developed compared to that of J2SE. 
                </p>
            </div>
        </div>
        <div class="chapter">
            <h2>5. The libraries CLDC</h2>
            <p>
                There are two categories of libraries CLDC.
                <br />
                In the first category includes classes J2SE. In the second, the class introduced by CLDC.
                <br />
		Classes in the first category fall within the packages java.lang .*, java.util .* and java.io. *. 
		These classes are derived from Java 2 Standard Edition version 1.3. They are identical to those of J2SE. 
		The semantics of classes and their methods will not change. 
		The methods () or protected (), which are not accessible to J2SE, did not add.
                <br />
            </p>
            <div class="subChapter">
                <h3>5.1. The class system</h3>
		The classes are linked internally by the virtual machine. 
		Some Java applications seeking the assistance of classes. 
		Example: J2SE Java compiler (javac), generating the code requires the presence of certain functions and String StringBuffer classes.
                <br />
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img src="./images/51.bmp" border="0" />
                        <br />
                    </span>
                </p>
                Classes representative types.
                <br />
                Each of these classes is under a multitude of classes of J2SE.
                <br />
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img src="./images/52.bmp" border="0" />
                        <br />
                    </span>
                </p>
                Collection classes.
                <br />
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img style="WIDTH: 477px; HEIGHT: 93px" height="93" src="./images/53.bmp" width="473" border="0" />
                        <br />
                    </span>
                </p>
                I/O classes.
                <br />
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img src="./images/54.bmp" border="0" />
                        <br />
                    </span>
                </p>
                Classes Reader, Writer, InputStreamReader and InputStreamWriter ensure support for internalization.
                <br />
                The mechanism of their work is the same as J2SE. His last two classes have the same manufacturers that in J2SE.
                <br />
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img src="./images/55.bmp" border="0" />
                        <br />
                    </span>
                </p>
                In cases where the String is present, use character encoding, whose name is entered in a variable microedition.encoding. 
		If the converter is not available, UnsupportedEncodingException appears.
                <br />
		It should be noted that CLDC does not support localization. So, this proves that all decisions related to the formatting of the date, 
		An hour, and so on. are outside the consideration of CLDC.
                <br />
            </div>
            <div class="subChapter">
                <h3>5.2.  Calendar and time</h3>
		CLDC includes a multitude of standard J2SE classes: 
		java.util.Calender, java.util.Date and java.util.TimeZone. By default, it maintains the same time zone.
                <br />
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img src="./images/56.bmp" border="0" />
                        <br />
                    </span>
                </p>
            </div>
            <div class="subChapter">
                <h3>5.3. The secondary classes</h3>
                Java.util.Random is a class which contains the number generator incidental. 
		Java.lang.Math has methods such as abs, max and min for the types int and long.
                <br />
            </div>
            <div class="subChapter">
                <h3>5.4. Exception &amp; Error</h3>
                <p align="center">
                    <span style="FONT-SIZE: 12pt; FONT-FAMILY: Times New Roman">
                        <img src="./images/57.bmp" border="0" />
                        <br />
                    </span>
                </p>
            </div>
        </div>
        <div class="chapter">
            <h2>6. Properties</h2>
            In CLDC there is no class java.util.Properties. However, a property can be accessed using the static method System.getProperty (String key). The minimum number of property given by CLDC is as follows:
            <br />
            <ul>
                <li>microedition.encoding</li>
                <li>microedition.platform</li>
                <li>microedition.configuration</li>
                <li>microedition.profiles</li>
                <ul>
                    <br />
                    The classes that belong to the second category are in packages Java.microedition .*.
                    <br />
                    The package javax.microedition.io introduces a new mechanism of support network.
                    <br />
                </ul>
            </ul>
        </div>
        <div class="chapter">
            <h2>7. CLDC Connection Framework</h2>
            Java.io. java.net .* * and are packages of J2SE not suitable for mobile because of their limited resources. That is why, it was developed a new package java.microedition.io. This package contains only one class: Connector, 8 interfaces and ConectionNotFoundException.
            <br />
            The class Connector - is the "heart" of Connection Framework. It has a series of static methods for receiving the subject of Connection. If the operation is successful, the method returns the object that realize the connection to the interface, or, IOException appears.
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="./images/71.bmp" />
                    <br />
                </span>
                <br />
                <i>The hierarchy of interfaces</i>
            </p>
            <br />
            The purpose performing connection to the interface can be received through the Connector class as stated above. The interface Connection has sole method close () which closes the connection to the network.
            <br />
            InputConnection is the interface that allows you to read the data. The methods openInputStream and openDataInputStream return data for reading.
            <br />
            OutputConnection is the interface that allows you to record data. The methods openOutputStream and openDataOutputStream return data for registration.
            <br />
            StreamConnection is the interface that met in itself InputConnection and OutputConnection.
            <br />
            ContentConnection is sub interface StreamConnection.
            <br />
            SteamConnectionNotified expects that the connection is established. The method acceptAndOpen () returns the object StreamConnection.
            <br />
            DatagrameConnection interface determines the connection datagram.
            <br />
            ConnectionNotFoundException s'apparaître when the connection can not be established.
            <br />
        </div>
        <div class="chapter">
            <h2>8. Connecter</h2>
            The parameter String belonging to the class method "open" to connect with the following format: "protocol: address: parameters".
            <br />
            <br />
            Examples of code:
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="./images/81.bmp" />
                    <br />
                </span>
            </p>
        </div>
        <div class="chapter">
            <h2>9. Security</h2>
            <p>
		One of the biggest advantages of Java is the dynamic loading of applications over the network at the customer using a mechanism 
		strong safety. The realization of this mechanism J2SE exceeds the resources JVM memory that supports CLDC. For the latter, 
		it was developed another mechanism that can be divided into two levels, one of the virtual machine and the application.
                <br />
               The level of virtual machine under implies that the application started in the virtual machine should be no possibility of damage 
		Motive. This condition provided by Java classfile Verifier must ensure that started byte code contains no links to areas 
		Invalid from memory. Verifier must reject the loading of these classes. Check is not the universal means against all problems. Its function is precisely to verify the byte code 
		In general, but it can not guarantee that the mobile will not be damaged by an application started. In J2SE, Security 
		Manager will take control over the application so that it can not go without authorization system, establish the connection, and so on. 
		But the motives may not perform such checks because of their limited resources. 
		In JVM that supports CLDC, was made a sandbox security model. Here, it is assumed that the application should be determined in an environment where they have access only 
		APIs, which were identified during the configuration process, in profiles and in the classroom allowed.
                <br />
                To be more precise, the sandbox model means that the files of the Java class started must pass the audit.
                <br />
                The loading of applications can be made with the native code for the virtual machine and can not achieve a class loader 
		The user. So, it is impossible to create its own class loader. The application can not load library native. The application can not have access to native functions that are available for 
		the virtual machine, and the native libraries that are not libraries maintained by CLDC Java, profiles and classes 
		Allowed. Achieving CLDC must ensure unable to restart packages system java .*, javax.microedition .*. 
		In addition, files can add their own restrictions to those mentioned above.
            </p>
        </div>
        <div class="chapter">
            <h2>10. MIDP</h2>
		Mobile Information Device Profile broadens CLDC by adding three new packages :
            <br />
            <ul>
                <li>javax.microedition.midlet</li>
                <li>javax.microedition.lcdui</li>
                <li>javax.microedition.rms</li>
            </ul>
            <br />
		It is required under certain conditions when installing the MIDlet. 
		It adds a series of classes to the already existing packages and determined in CLDC.
            <br />
            In the package java.io adding HttpConnection interface.
            <br />
            In the package java.lang adding IllegalStateException (java.lang.IllegalStateException).
            <br />
            It adds functionality that enables applications to create timers. To this end, it also added classes java.util.Timer and java.util.TimerTask just J2SE.
            <br />
            The main component of user interface is MIDP screen.
            <br />
        </div>
        <div class="chapter">
            <h2>11. Midlet</h2>
            Mobile Information Device Profile has no resemblance to the model introduced in J2SE Applet. MIDP introduced a new model built 
		Base CLDC, which allows the multitude of Java applications to start concurrently on KVM and share data.
            <br />
            Let us, therefore, consideration of MIDP on the most simple Hello World. His code is presented below.
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="data/resources/597/images/111.JPG" />
                    <br />
                </span>
            </p>
            The example given discuss it in detail:
            <br />
            <br />
		First, what we're doing is creating the class that produces an abstract class java.microedition.midlet.Midlet. To achieve this class, it is essential to achieve 3 abstract methods starApp, pauseApp and destroyApp. 3 These methods determine the life cycle midlet.
            <br />
            But first a few words on the history of the object creation MIDlet. In the model MIPD, the system awakens to the public 
		manufacturer without arguments to create an object MIDlet. If you want to give initials, that is precisely where we must enter the code.
            <br />
            <br />
           StarApp The method is called by the system to start or restart the midlet. Its purpose is the preparation of midlet at work, for example, 
		the allocation of resources and the creation of the user interface necessary. The method starApp can be completed in two ways is called 
		Transient and not transient. Transient, this is not a fatal case, the midlet can "tell" the system that was launched once again later. 
		For that the midlet returns a MIDletStateChangeException. Non-transient, is the case when it comes something extraordinary that has not been 
		planned, a problem, for example, an Error or RuntimeException. In this case, the midlet should destroy using the method destroyApp.
            <br />
            <br />
            These situations are presented below.
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="data/resources/597/images/112.JPG" />
                    <br />
                </span>
            </p>
            <br />
		PauseApp The method is called by the system to suspend the activity of midlet. In this situation, the midlet must stop and 
		make available the resources that it no longer needed. The latter is very important because the resources of KVM are quite limited. The method 
		pauseApp, in general, must operate at the same time that the method startApp.
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="data/resources/597/images/113.JPG" />
                    <br />
                </span>
            </p>
            <br />
           And the latter method destroyApp awakened by the system to "announce" the midlet, it will be destroyed and it is preparing to 
		the procedure: close resources and safeguard the necessary information.
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="data/resources/597/images/114.JPG" />
                    <br />
                </span>
            </p>
            <br />
        </div>
        <div class="chapter">
            <h2>12. Lifecycle of a Midlet</h2>
            Now turn to the study of life cycle midlet. When he paused, it may be one of 3 states :
            <br />
            <p align="center">
                <span style="font-size: 12.0pt; font-family: Times New Roman">
                    <img border="0" src="data/resources/597/images/121.JPG" />
                    <br />
                </span>
            </p>
            <div class="subChapter">
                <h3>12.1. Paused State</h3>
                In the state Paused State, the midlet can remain, first, it has just been created, and the method startApp has not yet been implemented 
		circuit / service, and then, as a result of calls for pauseApp or methods notifyPaused. Once the midlet have found this condition, 
		will make available the resources that it no longer needed. But it is still "alive" because it can always receive messages 
		asynchronous such as the Timer. However, it must be noted that the system can not achieve this state. For example 
		take a situation where the midlet was started, and at the same time the mobile received a call. In this case, the motive can simply "kill" 
		the virtual machine if this phone can not be achieved Paused state.
            </div>
            <div class="subChapter">
                <h3>12.2. Active State</h3>
                The midlet Active Since the state after the commissioning of the method startApp or, after leaving the state as a result of Paused 
		Call for resumeRequest.
            </div>
            <div class="subChapter">
                <h3>12.3. Destroyed State</h3>
                The state of Destroyed State, the midlet is found after the call to destroyApp or notifyDestroyed. Being in this state, can not midlet 
		Not move to another state. The transition from one state to another occurs through the system and the midlet itself.
                <br />
                <br />
                Now, summarizes information on six methods classes MIDlet. The seventh method, getAppProperty, is not 
		"Life cycle" of a midlet.
                <br />
                StartApp The method is called by the system to put a midlet in a state Active, or to put it back into service after 
		Paused state. We must not confuse the startApp method and the main method. The method startApp may be called more than once.
                <br />
                The method pauseApp which may be called by the system in two cases. If the mobile receives a call or, if it fails 
		memory. In the latter case, the midlet must "liberate" resources.
                <br />
                The method destroyApp is a way "normal" finish the job of midlet. This method has a parameter boolean (unconditional). 
		This shows whether the call is "unconditional". In other words, if the appeal is equal to fasle and is not midlet 
		ready to complete his work, he can "ask for life" system, having launched MIDletStateChangeException. The system then can 
		execute such request, so the state of midlet not change. 
		If the parameter is equal to true, the midlet must "obey" without "asking life", and make available all resources.
                <br />
                <br />
                The following three methods can be called by the same midlet to change its current status.
                <br />
                Using the method resumeRequest, midlet can initiate the transition from state to state Paused Active. This opportunity 
		may occur, for example, at the expiration of Timeout.
                <br />
                The method allows the notifyPaused midlet to move freely about the state Active in the Paused state.
                <br />
		The midlet can call the method notifyDistroyed to announce it has completed the work, stored data necessary 
		and made available resources, and with that method destroyApp will not be called.
                <br />
            </div>
        </div>
        <div class="chapter">
            <h2>Conclusion</h2>
            In conclusion, let me say a few words in support of Java technology or to be more precisely J2ME. In comparison with other 
		technologies, for example. NET, proposed by Microsoft, and so on. I think Sun technology brings more advantages: it is simple and easy 
		use (technical programming) to a broad level of users (as software and documentation). Java for mobile phones has a huge 
		potential especially through the use of mobile phones in daily life, which has already opened access to all areas and on the market 
		World. The use of Java (J2ME) in the mobile is increasingly popular among users and programmers.
            <br />
        </div>
    </body>
</html>

